package com.dx.VegetableOxygenBarBackEnd.websocket;

import javax.websocket.server.ServerEndpointConfig;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CustomConfigurator extends ServerEndpointConfig.Configurator {

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        // 添加跨域响应头
        response.getHeaders().put("Access-Control-Allow-Origin", List.of("https://danma.icu")); // 替换为允许的源
        response.getHeaders().put("Access-Control-Allow-Credentials", List.of("true"));
        super.modifyHandshake(sec, request, response);
    }
}
